Skip to content

Exposed getblocktemplate rpc via REST endpoint.#230

Draft
Randy808 wants to merge 1 commit into
Blockstream:new-indexfrom
Randy808:add-getblocktemplate
Draft

Exposed getblocktemplate rpc via REST endpoint.#230
Randy808 wants to merge 1 commit into
Blockstream:new-indexfrom
Randy808:add-getblocktemplate

Conversation

@Randy808

Copy link
Copy Markdown
Collaborator

No description provided.

@Randy808 Randy808 requested a review from EddieHouston June 24, 2026 20:34
Comment thread src/rest.rs Outdated
json_response(query.estimate_fee_map(), TTL_SHORT)
}

(&Method::GET, Some(&"getblocktemplate"), None, None, None, None) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest doing something more like /block-template instead so it looks less like an RPC passthrough (can give us flexibility in the future to change the object returned).

Comment thread src/rest.rs
result: errors::Result<JsonValue>,
) -> Result<Response<Full<Bytes>>, HttpError> {
match result {
Ok(template) => json_response(template, GETBLOCKTEMPLATE_TTL as u32),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably want to document that the endpoint is for block explorers and not mining work as the 15 second staleness could be an issue there.

Comment thread src/rest.rs
}
}

fn getblocktemplate_rpc_error(err: &errors::Error) -> Option<(i64, String)> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex review finding:

The Connection error handling here probably will not behave as intended.
Daemon::request() retries ErrorKind::Connection internally, so this REST error path is unlikely to see those errors.

For example, bitcoind warmup error -28 is converted into ErrorKind::Connection, which means /getblocktemplate would keep retrying instead of returning the intended 502 JSON response.

One related concern: Query::getblocktemplate() holds the block template cache mutex while making the daemon RPC call. If that RPC gets stuck retrying, later /getblocktemplate requests will block behind the same mutex.

@EddieHouston EddieHouston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks pretty good. Currently I don't think that electrs directly proxies through any other calls to bitcoin node (although I was just considering it for calls to GET /block//raw... so electrs doesn't cache all the txs in the raw block).

We might also consider adding a startup flag (--enable-mining-rest) to enable this.

@Randy808 Randy808 force-pushed the add-getblocktemplate branch from 6f61218 to a812004 Compare June 25, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants